#ifndef __CHANNEL_HPP__
#define __CHANNEL_HPP__

#include <iostream>
#include <string>
#include <unistd.h>

class Channel
{
public:
    Channel(int wfd, pid_t who)
        : _wfd(wfd), _who(who)
    {
        _name = "Channel——写端:" + std::to_string(_wfd) + "——子进程pid:" + std::to_string(_who);
    }

    ~Channel()
    {}

    std::string Name()
    {
        return _name;
    }

    pid_t Id()
    {
        return _who;
    }

    int Wfd()
    {
        return _wfd;
    }

    void Send(int task)
    {
        ::write(_wfd, &task, sizeof(task));
    }

    void Close()
    {
        ::close(_wfd);
    }

private:
    int _wfd;
    std::string _name;
    pid_t _who;
};

#endif